/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package wh.guistuff;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.util.ArrayList;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;

import wh.Manager;

/**
 * 
 * @author Geir
 */
public class MyJTable extends JTable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -4384130597424317215L;
	private static Color gridColor = new Color(150, 228, 255);
	private static Color rowColor = new Color(248, 248, 255); // Ghost white
	private static Color selrowColor = new Color(230, 230, 250);
	private static Color headerColor = new Color(255, 255, 224);
	private static Font cellFont = new Font("serif", Font.TRUETYPE_FONT, 18);
	
	
	public MyJTable(DefaultTableModel model) {
		
		super(model);
		initTable();
	}
	

	public void initTable() {
		
		setGridColor(gridColor);
		setRowHeight(20);
		setFont(cellFont);
		// getColumnModel().setColumnMargin(12);
		JTableHeader header = getTableHeader();
		header.setBackground(headerColor);
		header.setPreferredSize(new Dimension(60, 20));
		Dimension tableDim = new Dimension(400, 400);
		setPreferredScrollableViewportSize(tableDim);
	}

	@Override
	public boolean isCellEditable(int rowIndex, int colIndex) {
		return false; // Disallow the editing of any cell
	}

	@Override
	public Component prepareRenderer(TableCellRenderer renderer, int Index_row, int Index_col) {
		
		Component comp = super.prepareRenderer(renderer, Index_row, Index_col);
		// even index, selected or not selected
		if (Index_row % 2 == 0) {
			comp.setBackground(rowColor);
		} else {
			comp.setBackground(Color.white);
		}
		
		if ((isCellSelected(Index_row, Index_col) == true)) {
			
			Color background = comp.getBackground();
			
			if (background == rowColor || background == Color.white)
			{
				comp.setBackground(Manager.processFinishedColor);
			}
		}
		
		return comp;
	}
}
